/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} l1
 * @param {ListNode} l2
 * @return {ListNode}
 */
var mergeTwoLists = function (l1, l2) {
	//  判断是否为空链表
	if (!l1 || !l2) {
		return l1 || l2;
	}
	// 初始化一个新链表
	let head = new ListNode();
	// 暂存链表头
	let h = head;
	// 遍历到l1和l2都有值的时候
	while (l1 && l2) {
		if (l1.val < l2.val) {
			head.next = l1;
			l1 = l1.next;
		} else {
			head.next = l2;
			l2 = l2.next;
		}
		head = head.next;
	}
	// 把后面的接上
	if (l1) {
		head.next = l1;
	}
	if (l2) {
		head.next = l2;
	}
	return h.next;
};